<template>
  <div class="app-container">
    <agency-filter
      :downLoading="downloadLoading"
      :commSeleList="commSeleList"
      :commCaseSeleList="commCaseSeleList"
      @submit-form="submitFilterForm"
      @on-export="onClickExport"
    />
    <div style="padding: 10px 0;">
      <el-button-group>
        <el-button
          v-if="roleCheck('batch-lock')"
          type="danger"
          size="mini"
          @click="toggleMultipAcountLock(ids,1)"
        >批量锁定</el-button>
        <el-button
          v-if="roleCheck('batch-lock')"
          type="warning"
          size="mini"
          @click="toggleMultipAcountLock(ids,2)"
        >批量解锁</el-button>
        <el-button
          v-if="roleCheck('batch-modify-level')"
          type="danger"
          size="mini"
          @click="toggleMemberLevel(ids,1)"
        >批量修改层级</el-button>
        <el-button
          v-if="roleCheck('create-agent')"
          type="primary"
          size="mini"
          @click="openDialog({props:{},dialogName:staticDialogName5})"
        >创建代理</el-button>
      </el-button-group>
    </div>
    <el-table
      border
      class="el-table-align-center"
      :data="tableData.list"
      ref="multipleTable"
      height="540"
      v-loading="loading"
      element-loading-text="加载中..."
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" :selectable="defaultSelect"></el-table-column>
      <el-table-column label="代理账号" width="150" prop="username" fixed>
        <template slot-scope="{row}">
          <!-- to do .... -->
          <div
            type="text"
            v-if="roleCheck('detail-btn')"
            class="undeline-link"
            @click="handleViewDetail(row)"
          >
            <svg-icon v-if="[1,2].indexOf(row.status)>-1" :icon-class="'lock'" style="color: red;"></svg-icon>
            <span
              class="clipboard-btn"
              :data-clipboard-text="row.username"
              :class="{isInternal: row.proxyType === 1}"
            >{{row.username}}</span>
          </div>
          <div v-if="roleCheck({exclude:'detail-btn'})">
            <svg-icon v-if="[1,2].indexOf(row.status)>-1" :icon-class="'lock'" style="color: red;"></svg-icon>
            <span
              class="clipboard-btn"
              :data-clipboard-text="row.username"
              :class="{isInternal: row.proxyType === 1}"
            >{{row.username}}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="120" prop="reallyName" />
      <!--<el-table-column label="代理返佣模式" width="150" prop="rebateName"/>-->
      <el-table-column label="所属上级" width="150" prop="parentName">
        <template slot-scope="{row}">
          <span
            v-if="roleCheck('agency')"
            @click="openDialog({props:row,dialogName:staticDialogName9})"
          >{{row.parentName}}</span>
          <span v-if="roleCheck({exclude:'agency'})">{{row.parentName}}</span>
        </template>
      </el-table-column>
      <el-table-column label="玩家层级" width="150" prop="levelName" />
      <el-table-column label="手续费方案">
        <el-table-column label="本月" width="150" prop="feeRule">
          <template slot-scope="{row}">{{formatCommFeeName(row.feeRuleId)}}</template>
        </el-table-column>
        <el-table-column label="下月" width="150" prop="feeRule">
          <template slot-scope="{row}">{{formatCommFeeName(row.feeRuleNextId)}}</template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="佣金方案类型" width="150" prop="commMode">
        <template slot-scope="{row}">{{formatCommMode(row.commMode).name}}</template>
      </el-table-column>
      <el-table-column label="会员返佣方案(现金网)" width="150" prop="cashRule">
        <template slot-scope="{row}">
          <div v-if="row.commMode == 1">{{formatCommCaseName(row.cashRuleId)}}</div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <!-- to do .... -->
      <el-table-column label="代充返利方案">
        <el-table-column label="本月" width="150" prop="feeRule">
          <template slot-scope="{row}">{{formatAgentRechargeRebatePlansName(row.rechargeRuleId)}}</template>
        </el-table-column>
        <el-table-column label="下月" width="150" prop="feeRule">
          <template slot-scope="{row}">{{formatAgentRechargeRebatePlansName(row.rechargeRuleNextId)}}</template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="层级状态" width="120" prop="levelStatus">
        <template slot-scope="{row}">
          <el-tag v-if="row.levelStatus === 1" type="warning">已锁定</el-tag>
          <el-tag v-else type="success">未锁定</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="主账户余额" width="150" prop="balance">
        <template slot-scope="{row}">{{row.balance | currency}}</template>
      </el-table-column>
      <el-table-column label="上分额度" width="120">
        <template slot-scope="{row}">{{row.creditAmount | currency}}</template>
      </el-table-column>
      <el-table-column label="会员上分" width="120">
        <template slot-scope="{row}">{{row.payOutAmount | currency}}</template>
      </el-table-column>
      <el-table-column label="代理上分" width="120">
        <template slot-scope="{row}">{{row.proxyCreditedAmount | currency}}</template>
      </el-table-column>
      <el-table-column label="剩余上分" width="120">
        <template slot-scope="{row}">{{row.validAllocateAmount | currency}}</template>
      </el-table-column>
      <el-table-column label="会员代充状态" width="120">
        <template slot-scope="{row}">{{ row.creditStatus | toConverter('AGENCY_CREDIT_STATUS')}}</template>
      </el-table-column>
      <el-table-column label="下发状态" width="120">
        <template slot-scope="{row}">{{ row.proxyStatus | toConverter('AGENCY_CREDIT_STATUS')}}</template>
      </el-table-column>
      <!--<el-table-column label="剩余取款流水" width="150">-->
      <!--<template slot-scope="{row}">-->
      <!--{{row.leftAmount | currency}}-->
      <!--</template>-->
      <!--</el-table-column>-->
      <el-table-column label="注册时间" width="180">
        <template slot-scope="{row}">{{ row.registerDate | toTime}}</template>
      </el-table-column>
      <el-table-column label="注册IP" width="150" prop="registerIp">
        <template slot-scope="{row}">{{ row.registerIp}}</template>
      </el-table-column>
      <!--<el-table-column label="本次登录时间" width="150" prop="login_time">-->
      <!--<template slot-scope="{row}">{{ row.login_time | toTime}}</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column label="本次登录IP" width="150" prop="login_ip" />-->
      <el-table-column label="备注" width="150" prop="comment" fixed="right">
        <template slot-scope="{row}">
          <el-tooltip v-if="row.remark" effect="dark" :content="row.remark" placement="top">
            <div
              class="undeline-link text-nowrap"
              @click="openDialog({props:row,dialogName:staticDialogName})"
            >{{row.remark}}</div>
          </el-tooltip>
          <div
            v-else-if="roleCheck('backup') "
            class="undeline-link"
            @click="openDialog({props:row,dialogName:staticDialogName})"
          >{{'添加备注'}}</div>
        </template>
      </el-table-column>
      <el-table-column label="状态" width="120" prop="status">
        <template slot-scope="{row}">
          <el-tag v-if="row.status === 2" type="warning">间接锁定</el-tag>
          <el-tag v-else-if="row.status === 3 " type="info">审核中</el-tag>
          <el-tag v-else-if="row.status === 1 " type="danger">完全锁定</el-tag>
          <!-- <el-tag v-else-if="row.status === 4 " type="info">登录锁定</el-tag> -->
          <!-- <template v-else-if="row.status === 6 ">
            <el-tag type="warning">间接锁定</el-tag>
            <el-tag type="info">登录锁定</el-tag>
          </template>-->
          <el-tag v-else type="success">正常</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="300" fixed="right">
        <template slot-scope="{row}">
          <el-button v-if="roleCheck('edit-btn')" type="text" @click="handleEditDetail(row)">编辑资料</el-button>
          <el-button
            v-if="roleCheck('edit-commission')"
            type="text"
            @click="editComm(row,1)"
          >编辑手续费方案</el-button>
          <el-button
            v-if="roleCheck('edit-commission-chain')"
            type="text"
            @click="openDialog({dialogName: staticDialogName11, props: row })"
          >编辑佣金链</el-button>
          <el-button
            v-if="roleCheck('lock') && [1,2].indexOf(row.status) !== -1"
            type="text"
            @click="toggleAcountLock(row, 4)"
          >解锁</el-button>
          <el-button v-else-if="roleCheck('lock')" type="text" @click="toggleAcountLock(row,3)">锁定</el-button>
          <!-- 3.2 修改：公司上分设置、上分清算、代理上分设置，合并成授信与代充设置 -->
          <el-button v-if="roleCheck('credit')" type="text" @click="editComm(row,2)">(删)公司上分设置</el-button>
          <el-button
            v-if="roleCheck('credit-settlement')"
            type="text"
            @click="openDialog({dialogName: 'up-rank-liquidation', props: row })"
          >(删)代充清算</el-button>
          <el-button
            v-if="roleCheck('credit-agent')"
            type="text"
            @click="openDialog({dialogName: staticDialogName10, props: row })"
          >(删)代理上分设置</el-button>

          <el-button v-if="roleCheck('credit')" type="text" @click="openCreditAndProxySettingDialog(row)">(增)授信与代充设置</el-button>
          <el-button
            v-if="roleCheck('edit-commission')"
            type="text"
            @click="editComm(row,2)"
          >(增)编辑代充返利方案</el-button>
          <el-button
            v-if="roleCheck('edit-commission')"
            type="text"
            @click="openDialog({props:{row},dialogName:staticDialogName5})"
          >(增)修改代理类型</el-button>
          <el-button
            v-if="roleCheck('modify-level')"
            type="text"
            @click="toggleMemberLevel(row,2)"
          >修改层级</el-button>
          <el-button v-if="roleCheck('sync-agency-user')" type="text" @click="syncData(row)">同步</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="gridSizeChange"
        @current-change="gridCurrentChange"
        :current-page="filters.page"
        :page-sizes="gridPageSize"
        :page-size="filters.size"
        :layout="gridLayout"
        :total="tableData.total"
      ></el-pagination>
    </div>

    <custom-dialog
      v-if="dialogName === staticDialogName3"
      :visible="dialogVisible"
      returnButtonName="返回"
      :callback="resetCustomDialog"
    >
      <div slot="title">{{editTitle}}</div>
      <agency-edit-dialog v-if="dialogName === staticDialogName3" />
    </custom-dialog>
    <custom-dialog
      v-if="dialogName === staticDialogName2"
      :visible="dialogVisible"
      returnButtonName="返回"
      :callback="resetCustomDialog"
    >
      <div slot="title">{{viewTitle}}</div>
      <agency-detail :member="dialogProps" v-if="dialogName === staticDialogName2" />
    </custom-dialog>
    <custom-dialog
      v-if="dialogName === staticDialogName6"
      :visible="dialogVisible"
      returnButtonName="返回"
      :callback="submitFinished"
    >
      <div slot="title">代理审核</div>
      <agency-audit v-if="dialogName === staticDialogName6" />
    </custom-dialog>
    <custom-dialog
      v-if="dialogName === staticDialogName7"
      :visible="dialogVisible"
      returnButtonName="返回"
      :callback="submitFinished"
    >
      <div slot="title">代理域名</div>
      <agency-domain v-if="dialogName === staticDialogName7" />
    </custom-dialog>
    <apply-dialog />
    <comment-dialog
      :id="dialogProps.id"
      :row-data="dialogProps"
      v-if="dialogName === staticDialogName"
      v-model="dialogVisible"
      @submit="submitFinished"
    />
    <account-lock-dialog
      :lock-class="lockClass"
      :status="ids[0].status"
      :ids="idsList"
      v-if="dialogName === staticDialogName4"
      v-model="dialogVisible"
      @submit="accountLockSubmit"
    />
    <edit-agency-dialog
      :id="dialogProps.id"
      :row-data="dialogProps"
      v-if="dialogName === staticDialogName5"
      v-model="dialogVisible"
      @submit="submitFinished"
    />
    <edit-upper-score-dialog
      :row-data="dialogProps"
      v-if="dialogName === staticDialogName8"
      v-model="dialogVisible"
      @submit="submitFinished"
    />
    <!--<agency-dialog-->
    <!--:row-data="dialogProps"-->
    <!--v-if="dialogName === staticDialogName9"-->
    <!--:dialogVisible="dialogVisible"-->
    <!--@cancel="cancel"-->
    <!--@submit="submitFinished"/>-->
    <configuration-lines-dialog
      :row-data="dialogProps"
      v-if="dialogName === staticDialogName10"
      v-model="dialogVisible"
      @submit="submitFinished"
    />

    <up-rank-liquidation
      v-if="dialogName === 'up-rank-liquidation'"
      :row-scope-data="dialogProps"
      v-model="dialogVisible"
      :id="dialogProps.id"
      @submit="submitFinished"
    />
    <EditCommChainDialog
      v-if="dialogName === staticDialogName11"
      :row-scope-data="dialogProps"
      v-model="dialogVisible"
      :id="dialogProps.id"
      :rowData="dialogProps"
      @submit="submitFinished"
    />
    <member-level-dialog
      v-model="memberLevelVisible"
      :idList="levelList"
      :type="levelType"
      @cancel="memberLevelVisible = false"
      @submit="submitFinished"
    />
    <!-- 授信与代充设置窗口 -->
    <credit-and-proxy-setting-dialog
      v-if="dialogName === staticDialogName12"
      :row-data="dialogProps"
      v-model="dialogVisible"
      @submit="submitFinished"
    />
    <editing-fee-plan-dialog
      v-if="dialogName === staticDialogName13"
      :id="dialogProps.id"
      :row-data="dialogProps"
      v-model="dialogVisible"
      @submit="submitFinished"
    />
  </div>
</template>
<script>

// constants
import { FILTER_ALL_TYPE } from '@/const/agencyEnum';

// utils
import { formatCommMode, mapToArray } from '@/utils/base';

// components
import CustomDialog from '@/components/customDialog/index';
import agencyDetail from '../detail/index';
import AgencyAudit from '../audit/index';
import AgencyDomain from '../domain/index';
import AgencyFilter from './form-filter';
import AgencyEditDialog from './editDialog';
import ApplyDialog from './applyDialog';
import CommentDialog from './commentDialog';
import AccountLockDialog from './accountLockDialog';
import EditAgencyDialog from './editAgencyDialog';
// import AgencyDialog from './agencyDialog';
import EditUpperScoreDialog from './editUpperScoreDialog';
import ConfigurationLinesDialog from './configurationLinesDialog';
import UpRankLiquidation from './upRankLiquidation';
import EditCommChainDialog from './editCommChainDialog';
import memberLevelDialog from './memberLevelDialog';
import creditAndProxySettingDialog from './creditAndProxySettingDialog';
import editingFeePlanDialog from './editingFeePlanDialog';

// service
import {
  getMemberList, setMembersStatus, exportMembershipList, memberSyncData,
} from '@/services/api/member';
import {
  getCommissionSelect,
  getCommissionCaseSelectList,
  agentRechargeRebatePlansList,
} from '@/services/api/commission';

// mixins
import { form, grid, dialog } from '@/build';

const headerMap = {
  username: '代理账号',
  reallyName: '姓名',
  parentName: '所属上级',
  formatPrevFeeRule: '手续费方案(本月)',
  formatCurrFeeRule: '手续费方案(下月)',
  formatCommName: '佣金方案类型',
  cashRule: '会员反佣方案(现金网)',
  formatBalance: '主账户余额',
  formatCreditAmount: '上分额度',
  formatMemberCreditAmount: '会员上分',

  formatProxyCreditedAmount: '代理上分',
  formatBalanceCreditAmount: '剩余上分',
  formatCreditStatus: '会员代充状态',
  formatProxyStatus: '下发状态',
  formatRegisterDate: '注册时间',
  registerIp: '注册IP',
  remark: '备注',
  formatStatus: '状态',
};

export default {
  name: 'agency-list',
  mixins: [form, grid, dialog],
  components: {
    EditUpperScoreDialog,
    AgencyDomain,
    AgencyAudit,
    EditAgencyDialog,
    AccountLockDialog,
    CommentDialog,
    ApplyDialog,
    AgencyEditDialog,
    agencyDetail,
    CustomDialog,
    AgencyFilter,
    // AgencyDialog,
    UpRankLiquidation,
    ConfigurationLinesDialog,
    EditCommChainDialog,
    memberLevelDialog,
    creditAndProxySettingDialog,
    editingFeePlanDialog,
  },
  data() {
    return {
      filters: {
        size: 20,
        page: 1,
        userType: 1,
        searchType: 1,
        startDate: moment(consts.ONLINE_DATE).format('YYYY-MM-DD HH:mm:ss'),
        endDate: moment().format('YYYY-MM-DD 23:59:59'),
      },
      tableData: {},
      ids: [],
      lockClass: 0,
      editTitle: '',
      viewTitle: '',
      staticDialogName: 'comment-dialog',
      staticDialogName2: 'agency-detail',
      staticDialogName3: 'agency-edit-dialog',
      staticDialogName4: 'agency-lock-dialog',
      staticDialogName5: 'edit-agency-dialog',
      staticDialogName6: 'agency-audit',
      staticDialogName7: 'agency-domain',
      staticDialogName8: 'edit-upper-score-domain',
      staticDialogName9: 'proxy-dialog',
      staticDialogName10: 'configuration-lines-dialog',
      staticDialogName11: 'edit-comm-chain-dialog',
      staticDialogName12: 'credit-and-proxy-setting-dialog',
      staticDialogName13: 'editing-fee-plan-dialog',
      filterDateType: false,
      commSeleList: [],
      agentRechargeRebatePlansList: [],
      commCaseSeleList: [],
      memberLevelVisible: false,
      levelType: 1,
      levelList: [],
      username: '',
      lockForm: {
      },
    };
  },
  watch: {
    $route: {
      handler(next) {
        if (next.query.audit) {
          this.openDialog({ props: {}, dialogName: this.staticDialogName6 });
        }
      },
      immediate: true,
    },
  },
  computed: {
    idsList() {
      return this.ids.map(item => item.id);
    },
  },
  methods: {
    cancel() {
      this.dialogVisible = false;
    },
    // 授信与代充设置
    openCreditAndProxySettingDialog(row) {
      this.openDialog({ props: row, dialogName: this.staticDialogName12 });
    },
    // 表格前面的checkbox操作
    handleSelectionChange(val) {
      this.ids = val;
    },
    defaultSelect(row) {
      if (row.lockStatus === 1) {
        return false;
      }
      return true;
    },
    // 显示查看账号详情
    handleViewDetail(row) {
      this.openDialog({ props: row, dialogName: this.staticDialogName2 });
      window.scrollTo(0, 0);
      this.viewTitle = `代理名称：${row.username ? row.username : row.blackTitle}`;
      this.$store.commit(types.SET_MEMBER_ID, row.id);
      this.$store.commit(types.SET_MEMBER_INFO, row);
    },
    resetCustomDialog() {
      this.$store.commit(types.SET_MEMBER_ID, 0);
      this.closeDialog();
    },
    // 显示编辑账号详情
    handleEditDetail(row) {
      if (this.checkOper(row)) {
        return;
      }
      this.openDialog({ props: row, dialogName: this.staticDialogName3 });
      window.scrollTo(0, 0);
      this.editTitle = `编辑资料：${row.username}`;
      this.$store.commit(types.SET_MEMBER_ID, row.id);
    },
    toggleMultipAcountLock(ids, lockClass) {
      if (ids.length === 0) {
        this.$message({
          type: 'warning',
          message: '请选中需要处理的数据',
        });
        return;
      }
      this.ids = ids;
      this.lockClass = lockClass;
      this.openDialog({ props: {}, dialogName: this.staticDialogName4 });
    },
    toggleAcountLock(row, lockClass) {
      if (this.checkOper(row)) {
        return;
      }
      this.$refs.multipleTable.clearSelection();
      this.lockClass = lockClass;
      this.ids = [row];
      this.openDialog({ props: row, dialogName: this.staticDialogName4 });
    },
    toggleMemberLevel(ids, type) {
      let levelList = [];
      if (type === 1) {
        levelList = ids;
      } else {
        levelList.push(ids);
      }
      if (levelList.length === 0) {
        this.$message({
          type: 'warning',
          message: '请选中需要处理的数据',
        });
        return;
      }
      this.levelList = levelList;
      this.levelType = type;
      this.memberLevelVisible = true;
    },
    editComm(row, type) {
      if (this.checkOper(row)) {
        return;
      }
      let dialogName;
      switch (type) {
        case 1:
          dialogName = this.staticDialogName13;
          break;
        case 2:
          dialogName = this.staticDialogName8;
          break;
        default:
          break;
      }
      // const dialogName = type === 1 ? this.staticDialogName5 : this.staticDialogName8;
      this.openDialog({ props: row, dialogName });
    },
    // 导出
    async onClickExport(formInline) {
      try {
        this.downloadLoading = true;
        this.formatData(formInline);
        const [status, result] = await exportMembershipList(this.filters);
        if (!status) throw new Error(result.message);
        const filename = '代理报表.csv';
        const header = mapToArray(headerMap);
        const filterField = Object.keys(headerMap);
        const exportData = this.formatList(result.list);
        this.export2Excel(header, filterField, exportData, filename);
      } catch (e) {
        this.$message({
          message: `${e.message || ''}`,
          type: 'error',
        });
      } finally {
        this.downloadLoading = false;
      }
    },
    formatList(data) {
      return data.map(item => ({
        ...item,
        formatPrevFeeRule: this.formatCommFeeName(item.feeRuleId),
        formatCurrFeeRule: this.formatCommFeeName(item.feeRuleNextId),
        formatCommName: this.formatCommMode(item.commMode).name,
        cashRule: item.commMode === 1 ? this.formatCommCaseName(item.cashRuleId) : '--',
        formatBalance: _.currency(item.balance),
        formatCreditAmount: _.currency(item.creditAmount),
        formatMemberCreditAmount: _.currency(item.memberCreditAmount),
        formatProxyCreditedAmount: _.currency(item.proxyCreditedAmount),
        formatBalanceCreditAmount: _.currency(item.balanceCreditAmount),
        formatCreditStatus: _.toConverter(item.creditStatus, 'AGENCY_CREDIT_STATUS'),
        formatProxyStatus: _.toConverter(item.proxyStatus, 'AGENCY_CREDIT_STATUS'),
        formatRegisterDate: _.toTime(item.registerDate),
        formatStatus: this.formatStatus(item.status),
      }));
    },
    checkOper(row) {
      if (row.lockStatus === 1) {
        this.$message({
          type: 'warning',
          message: '该用户已有未审核的操作',
        });
        return true;
      }
      return false;
    },
    accountLockSubmit(lockForm) {
      if (lockForm.type.includes(7)) {
        lockForm.type = 7;
      } else {
        lockForm.type = lockForm.type.join(',');
      }
      // lockForm.effectScope = lockForm.effectScope.join(',');
      lockForm.ids = this.idsList;
      lockForm.lockClass = this.lockClass;
      this.lockForm = { ...lockForm };
      this.doSave({ action: 'saveLock' });
    },
    submitFilterForm(formInline) {
      this.formatData(formInline);
      this.gridSearch();
    },
    formatData(formInline) {
      const { time } = formInline;
      if (!_.isUndefined(time) && _.isArray(time)) {
        const [startDate, endDate] = time;
        formInline = { ...formInline, startDate, endDate };
      } else {
        this.filters.startDate = undefined;
        this.filters.endDate = undefined;
      }
      this.filters = { ...this.filters, ...formInline };
    },
    formatCommFeeName(id) {
      if (!(this.commSeleList.length && id)) return '';
      const map = this.commSeleList.find(item => item.id === id);
      if(!map){
        return '默认方案';
      }
      return map.name || '';
    },
    formatCommCaseName(id) {
      if (!(this.commCaseSeleList.length && id)) return '';
      const map = this.commCaseSeleList.find(item => item.id === id);
      return map.name || '';
    },
    formatAgentRechargeRebatePlansName(id) {
      if (!(this.agentRechargeRebatePlansList.length && id)) return '-未设置方案-';
      const map = this.agentRechargeRebatePlansList.find(item => item.id === id);
      return map.name || '-未设置方案-';
    },
    formatStatus(status) {
      switch (status) {
        case 1:
          return '完全锁定';
        case 2:
          return '间接锁定';
        case 3:
          return '审核中';
        // case 4:
        //   return '登录锁定';
        default:
          return '正常';
      }
    },
    formatCommMode,
    formatFeeRule(feeRule) {
      if (!(Array.isArray(feeRule) && feeRule.length)) return {};
      return {
        prevMonth: feeRule[0].name,
        currMonth: feeRule[1].name,
      };
    },
    syncData(row) {
      this.username = row.username;
      this.doSave({ action: 'syncUserData' });
    },
  },
  mounted() {
    this.bindGet(getMemberList, 'tableData', {
      action: 'getGrid',
      sendingData: 'filters',
      format: (data) => {
        data.list.forEach((item) => {
          item.remark = item.remark.replace(/\s+/g, '');
        });
        return data;
      },
    });
    this.bindGet(getCommissionSelect, 'commSeleList', {
      format: (data) => {
        if (!(Array.isArray(data) && data.length)) return [];
        data.unshift(FILTER_ALL_TYPE);
        return data;
      },
    });
    // 获取返利返充方案列表
    this.bindGet(agentRechargeRebatePlansList, 'agentRechargeRebatePlansList', {
      format: (data) => {
        if (!(Array.isArray(data) && data.length)) return [];
        data.unshift(FILTER_ALL_TYPE);
        return data;
      },
    });
    this.bindGet(getCommissionCaseSelectList, 'commCaseSeleList', {
      format: (data) => {
        if (!(Array.isArray(data) && data.length)) return [];
        data.unshift(FILTER_ALL_TYPE);
        return data;
      },
    });
    this.getAll();

    this.bindSave(memberSyncData, 'syncUserData', 'username', {
      successMessage: '同步成功',
      beforeSend: data => ({ username: data }),
      afterSuccess: ([result]) => {
        if (result) {
          this.doGet({ action: 'getGrid' });
        }
      },
    });
    this.bindSave(setMembersStatus, 'saveLock', 'lockForm', {
      afterSuccess: ([result, data]) => {
        this.dialogVisible = false;
        if (result) {
          if (data.failNum > 0 && [3, 4].indexOf(this.lockClass) != -1) {
            this.$message({
              type: 'success',
              message: `${this.lockClass == 3 ? '锁定' : '解锁'}失败,失败原因：${data.failMessage}`,
            });
          }

          if (data.failNum > 0 && data.successNum < 1 && [3, 4].indexOf(this.lockClass) == -1) {
            this.$message({
              type: 'success',
              message: `失败批量${this.lockClass == 1 ? '锁定' : '解锁'}${data.failNum}个操作,失败原因：${data.failMessage}`,
            });
          } else if (data.failNum > 0 && data.successNum > 0 && [3, 4].indexOf(this.lockClass) == -1) {
            this.$message({
              type: 'success',
              message: `成功批量${this.lockClass == 1 ? '锁定' : '解锁'}${data.successNum}个操作，失败批量${this.lockClass == 1 ? '锁定' : '解锁'}${data.failNum}个操作,失败原因：${data.failMessage}`,
            });
          } else if (data.failNum < 1 && data.successNum > 0 && [3, 4].indexOf(this.lockClass) == -1) {
            this.$message({
              type: 'success',
              message: `成功批量${this.lockClass == 1 ? '锁定' : '解锁'}${data.successNum}个操作`,
            });
          }
          this.gridSearch();
        }
      },
    });


    const { member } = this.$route.params;
    if (member) {
      const { usernameRisk } = member || member.blackTitle;
      const obj = {
        ...member,
        username: usernameRisk,
        id: member.userId,
      };
      this.handleViewDetail(obj);
    }
  },
};

</script>
<style lang="scss">
.el-table-align-center {
  &.el-table {
    width: 100%;
    text-align: center !important;
    th {
      text-align: center !important;
    }
  }
}

.undeline-link {
  display: block;
  text-align: center;
  text-decoration: underline;
  cursor: pointer;
  color: #409eff;
}

.isInternal {
  color: red;
}
</style>
